package net;

import org.junit.Test;

import java.io.*;
import java.net.Socket;

public class SocketFileUploadTest {

    @Test
    public void testSocketV1() throws IOException {
        Socket socket = new Socket("localhost", 8888);
        OutputStream outputStream = socket.getOutputStream();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("D:/a.jpeg"));
        byte[] buff = new byte[1024];
        int length = 0;
        while ((length = bufferedInputStream.read(buff))!=-1){
            outputStream.write(buff, 0, length);
        }
        //文件上传完毕后,关闭输出流,否则服务器会一直处于等待状态
        socket.shutdownOutput();
        InputStream inputStream = socket.getInputStream();
        length = inputStream.read(buff);
        System.out.println("服务端返回:"+new String(buff, 0, length));
    }


}
